home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Other View Systems / MacApp Views / FWMARead.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.9 KB  |  215 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMARead.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMAREAD_H
  11. #define FWMAREAD_H
  12.  
  13. #ifndef FWTCOLL_H
  14. #include "FWTColl.h"
  15. #endif
  16.  
  17. #ifndef FWPOINT_H
  18. #include "FWPoint.h"
  19. #endif
  20.  
  21. #ifndef FWSTRING_H
  22. #include "FWString.h"
  23. #endif
  24.  
  25. //========================================================================================
  26. // Forward declarations
  27. //========================================================================================
  28.  
  29. class FW_CReadableStream;
  30. class FW_CSuperView;
  31. class FW_CFrame;
  32. class FW_MReceiver;
  33. class FW_CScrollBarScroller;
  34. class FW_CRadioCluster;
  35. struct Environment;
  36. class FW_CMAEventHandler;
  37. class FW_CMAView;
  38. class FW_CMAScrollBarScroller;
  39. class FW_CMAClassCollection;
  40. class FW_CMAObject;
  41. class FW_PResourceFile;
  42. class FW_PFileSpecification;
  43. class FW_CFont;
  44. class FW_CColor;
  45.  
  46. //========================================================================================
  47. //     Types & Constants
  48. //========================================================================================
  49.  
  50. // MacApp resource types
  51. #define FW_kMAType            'View'
  52. #define FW_kWINDType        'WIND'
  53.  
  54. // MacApp class signatures, from UMacAppGlobals.h
  55. const ResType kStdDocument = 'docu';
  56. const ResType kStdTracker = 'trak';
  57. const ResType kStdList = 'list';
  58.  
  59. const ResType kStdButton = 'butn';
  60. const ResType kStdCheckBox = 'chkb';
  61. const ResType kStdCluster = 'clus';
  62. const ResType kStdControl = 'cntl';
  63. const ResType kStdDefaultView = 'dflt';
  64. const ResType kStdDialogBehavior = 'dlgb';
  65. const ResType kStdDialogView = 'dlog';
  66. const ResType kStdDialogTEView = 'dtev';
  67. const ResType kStdDrawingEnvironment = 'drwe';
  68. const ResType kStdEditText = 'edit';
  69. const ResType kStdGridView = 'grid';
  70. const ResType kStdIcon = 'icon';
  71. const ResType kStdIncludeAt = 'inc@';
  72. const ResType kStdNumberText = 'nmbr';
  73. const ResType kStdPattern = 'patn';
  74. const ResType kStdPicture = 'pict';
  75. const ResType kStdPopup = 'popp';
  76. const ResType kStdRadio = 'radb';
  77. const ResType kStdScroller = 'scrl';
  78. const ResType kStdScrollBar = 'sbar';
  79. const ResType kStdScrollerScrollBar = 'ssbr';
  80. const ResType kStdSmallIcon = 'sicn';
  81. const ResType kStdStaticText = 'stat';
  82. const ResType kStdTabTEView = 'ttev';
  83. const ResType kStdTEView = 'tevw';
  84. const ResType kStdTextGridView = 'txtg';
  85. const ResType kStdTextListView = 'lstg';
  86. const ResType kStdView = 'view';
  87. const ResType kStdWindow = 'wind';
  88. const ResType kStdTargetBorderView = 'tbor';
  89.  
  90. const ResType kNullSignature = '    ';
  91.  
  92. typedef FW_CMAObject*    (*MAClassCreatorFunc)(ResType);
  93.  
  94. #pragma options align=mac68k
  95.  
  96. typedef struct MAClassTable {
  97.     ResType                classID;
  98.     MAClassCreatorFunc    creatorFunc;
  99. } MAClassTable, *MAClassTableP, **MAClassTableH;
  100.  
  101. #pragma options align=reset
  102.  
  103. // New ODF error (to move later to FWErrors.h).  Also defined in FWPPobRead.h
  104. #ifndef FW_xWrongViewResourceVersion
  105. #define FW_xWrongViewResourceVersion     -30215
  106. #endif
  107.  
  108. // Macro
  109. #define MACAPP_WARNING(str)  if(FW_CMacAppReader::gUseDebugWarnings) FW_DEBUG_MESSAGE(str)
  110.  
  111. //========================================================================================
  112. // class FW_CMacAppReader
  113. //========================================================================================
  114.  
  115. class    FW_CMacAppReader {
  116. public:
  117.     enum ENextObjectType { kView, kBehavior, kDrawingEnv, kAdorner };
  118.     enum EResourceFileKind { kPartOnly, kPartOrAskUser, kCurrentResFile, kNewResFile };
  119.     enum EErrorKind { kNoError, kNoViewResource, kStreamReadError, kWrongVersion };
  120.  
  121.     // Class registration
  122.     static void             RegisterAllMacAppClasses();
  123.     static void             RegisterSignature(ResType classID, MAClassCreatorFunc inCreatorFunc);
  124.     static void             RegisterClassName(FW_CString& className, MAClassCreatorFunc creatorFunc);
  125.  
  126.     // Main entry point to load MacApp views
  127.     static FW_PlatformError    CreateSubViewsFromMacAppResource(Environment* ev, 
  128.                                                             FW_ResourceID resourceID, 
  129.                                                             FW_CSuperView* superview,
  130.                                                             FW_MReceiver* receiver,
  131.                                                             EResourceFileKind resFileKind,
  132.                                                             FW_Boolean useDebugWarnings = true);
  133.  
  134.     // Dynamic reloading of views
  135.     static FW_PlatformError ReloadViews(Environment* ev, 
  136.                                         FW_ResourceID resourceID, 
  137.                                         FW_CFrame* frame, 
  138.                                         FW_MReceiver* receiver,
  139.                                         EResourceFileKind resFileKind,
  140.                                         FW_Boolean useDebugWarnings = true);
  141.  
  142.     // Utilities 
  143.     static FW_PResourceFile* GetResFile(Environment* ev, EResourceFileKind resFileKind);
  144.     static FW_Boolean        HasResFile() { return (gCurResFileSpec != 0); } ;
  145.     static void                GetResFileName(Environment* ev, FW_CString& name);
  146.     static FW_CString         ReadStr255(FW_CReadableStream& stream);
  147.     static void             GetTextStyle(short textStyleID, FW_CFont& font, FW_CColor& color);
  148.  
  149.     // For internal use
  150. protected:
  151.     static void                ReadStreamObject(Environment* ev, 
  152.                                             FW_CReadableStream& inStream, 
  153.                                             FW_CSuperView* superview, 
  154.                                             FW_MReceiver* receiver,
  155.                                             ENextObjectType type);    
  156.         
  157. private:
  158.     static FW_CMAObject*     ReadStdObject(Environment* ev, FW_CReadableStream& stream, ENextObjectType type);
  159.     static FW_CMAObject*     ReadObject(Environment* ev, FW_CReadableStream& stream);
  160.     static short            FetchClassIndex(ResType classID);
  161.     static FW_CMAObject*     NewBySignature(ResType classID);
  162.     static FW_CMAObject*     NewByClassName(FW_CString& className, ResType classID);
  163.     static void             PostCreateViewFromStream(Environment* ev, FW_CSuperView* view);
  164.  
  165.     // Class globales
  166. public:
  167.     static FW_CMAScrollBarScroller*        gScroller;
  168.     static FW_CRadioCluster*            gCluster;
  169.     static FW_CPoint                    gOffset;
  170.     static ResType                        gDefaultButtonID;
  171.     static ResType                        gCancelButtonID;
  172.  
  173. private:
  174.     static short                        gClassCount;
  175.     static MAClassTableH                gTableH;
  176.     static FW_CMAClassCollection*        gClassCollection;
  177.     static FW_PFileSpecification*        gCurResFileSpec;
  178.     static FW_Boolean                    gUseDebugWarnings;
  179.     
  180.     friend FW_CMAEventHandler;
  181.     friend FW_CMAView;
  182. };
  183.  
  184. //========================================================================================
  185. // class FW_CMacAppClassDesc
  186. //========================================================================================
  187.  
  188. class    FW_CMAClassDesc {
  189. public:
  190.     FW_DECLARE_AUTO(FW_CMAClassDesc)
  191.  
  192.     FW_CMAClassDesc(FW_CString& className, MAClassCreatorFunc creator) :
  193.                     fClassName(className), fClassCreator(creator) { };
  194.     ~FW_CMAClassDesc() {};
  195.     
  196.     FW_CString            fClassName;
  197.     MAClassCreatorFunc    fClassCreator;
  198. };
  199.  
  200. //========================================================================================
  201. // class FW_CMAClassCollection
  202. //========================================================================================
  203.  
  204. class FW_CMAClassCollection : public FW_TOrderedCollection<FW_CMAClassDesc>
  205. {
  206. public:
  207.     FW_DECLARE_AUTO(FW_CMAClassCollection)
  208.     
  209.     FW_CMAClassCollection() : FW_TOrderedCollection<FW_CMAClassDesc>(){}
  210.     ~FW_CMAClassCollection() {}
  211. };
  212.  
  213.  
  214. #endif
  215.